package com.liao.seckill.dao;

import com.liao.seckill.pojo.TbGoodsMiaosha;
import com.liao.seckill.pojo.TbGoodsMiaoshaAndGoods;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
public interface GoodsMiaoShaDao extends CrudRepository<TbGoodsMiaosha,Integer> {


    @Query(value = "select new com.liao.seckill.pojo.TbGoodsMiaoshaAndGoods(g,gm) from TbGoods g,TbGoodsMiaosha gm where gm.goodsId = g.id")
    List<TbGoodsMiaoshaAndGoods> findTbGoodsMiaoshaAndGoods();

    @Modifying
    @Query("update TbGoodsMiaosha gm set gm.stockCount = gm.stockCount - 1 where gm.id = ?1 and gm.stockCount > 0")
    int stockSub(Integer id);
}
